//
//  HTPremiumPackageSection.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/8.
//

import SwiftUI

struct HTPremiumPackageSection: View {

  @EnvironmentObject private var var_store: HTAppStore

  var body: some View {
    VStack(alignment: .leading){
      ScrollView(.horizontal, showsIndicators: false){
        HStack(spacing: UIDevice.ht_fixToWidth(width: 5)){
          ForEach(0..<(var_store.state.var_subscribeState.var_subscribes ?? []).count, id: \.self) {index in
            let var_subscribe = (var_store.state.var_subscribeState.var_subscribes ?? [])[index]
            HTPackageItem(var_subscribe: var_subscribe, var_isSel: var_store.state.var_subscribeState.var_selSubscribe?.var_productIdentifier == var_subscribe.var_productIdentifier)
              .onTapGesture {
                var_store.dispatch(HTEnumSubscribeAction.htEnumSelSub(var_selSub: var_subscribe))
              }
          }
        }
      }
      Text(var_store.state.var_subscribeState.var_selSubscribe!.ht_selTip() ?? "")
        .font(.system(size: 12))
        .foregroundColor(Color(hex: "#FF6C3C")) +
      Text("\(var_store.state.var_subscribeState.var_selSubscribe!.ht_selTip() != "" ? "" : "* ")you can cancel anytime")
        .font(.system(size: 12))
        .foregroundColor(Color(hex: "#999999"))
    }
    .frame(maxWidth: .infinity, alignment: .leading)
  }
}
